<?php
/*
*
* oa.oaBusinessTrip  oa系统-频道模型
*
* ----------------------------------------------
* 零起飞网络 - 专注于企业管理系统开发
* 以质量求生存，以服务谋发展，以信誉创品牌 !
* ----------------------------------------------
* @copyright	Copyright (C) 2017-2018 07FLY Network Technology Co,LTD All rights reserved.
* @license    For licensing, see LICENSE.html
* @author ：kfrs <goodkfrs@QQ.com> 574249366
* @version ：1.0
* @link ：http://www.07fly.xyz
*/

namespace app\workflow\controller;

/**
 * 出差申请管理-控制器
 */
class OaBusinessTrip extends WorkflowBase
{

    /**
     * 出差申请列表=》模板
     * @return mixed|string
     */
    public function show()
    {
        if (!empty($this->param['listtype'])) {
            $this->assign('listtype', $this->param['listtype']);
        } else {
            $this->assign('listtype', 'self_create');
        }
        $this->common_data();
        return $this->fetch('show');
    }

    /**
     * 出差申请列表-》json数据
     * @return
     */
    public function show_json()
    {
        $where = [];
        $where = $this->logicOaBusinessTrip->getWhere($this->param);
        $list = $this->logicOaBusinessTrip->getOaBusinessTripList($where);
        return $list;
    }


    /**
     * 出差申请添加
     * @return mixed|string
     */
    public function add()
    {
        IS_POST && $this->jump($this->logicOaBusinessTrip->oaBusinessTripAdd($this->param));
        $this->common_data();
        return $this->fetch('add');
    }

    /**
     * 出差申请编辑
     * @return mixed|string
     */

    public function edit()
    {
        IS_POST && $this->jump($this->logicOaBusinessTrip->oaBusinessTripEdit($this->param));
        $info = $this->logicOaBusinessTrip->getOaBusinessTripInfo(['id' => $this->param['id']]);
        $this->assign('info', $info);
        $this->common_data();
        return $this->fetch('edit');
    }

    /**
     * 出差申请删除
     */
    public function del()
    {
        $where = empty($this->param['id']) ? ['id' => 0] : ['id' => $this->param['id']];
        $this->jump($this->logicOaBusinessTrip->oaBusinessTripDel($where));
    }


    /**
     * 详细
     * @return mixed|string
     */

    public function detail()
    {
        $info = $this->logicOaBusinessTrip->getOaBusinessTripInfo(['id' => $this->param['id']]);
        $workflow=$this->logicWorkflowBusinessHistory->getWorkflowBusinessHistoryLog(['business_id' => $this->param['id'],'business_type'=>'oa_business_trip']);
        $this->assign('info', $info);
        $this->assign('workflow', $workflow);
        $this->common_data();
        return $this->fetch('detail');
    }


    /**
     * 提交审批
     */
    public function audit_send()
    {
        IS_POST && $this->jump($this->logicOaBusinessTrip->setAuditSend($this->param));

        //内部接口调用=》提交看审批
        $postdata['business_type'] = 'oa_business_trip';
        $rpcurl = url('workflow/rpc.RpcApi/getWorkFlowList',$postdata);
        $res = httpRpc($rpcurl);
        $audit_workflow_list = [];
        if ($res['code'] == 1) {
            $audit_workflow_list = $res['data'];
        }
        $this->assign('id', $this->param['id']);
        $this->assign('audit_workflow_list', $audit_workflow_list);

        return $this->fetch('audit_send');

    }

    /**
     * 取消审核
     */
    public function audit_cancel()
    {
        $this->jump($this->logicOaBusinessTrip->setAuditCancel($this->param));
    }

    /**
     * 审核详细
     */
    public function audit_detail()
    {
        $intedata['business_type'] = 'oa_business_trip';
        $intedata['business_id'] = $this->param['id'];
        //内部接口调用=》提交看审批
        $rpcurl = url('workflow/rpc.RpcApi/getWorkflowBusinessInfo', $intedata);
        $res = httpRpc($rpcurl);
        $this->assign('info', $res['data']);
        return $this->fetch('audit_detail');
    }


    /**
     * 公共数据
     * Author: lingqifei created by at 2020/6/15 0015
     */
    public function common_data()
    {

        $sys_user = $this->logicSysUser->getSysUserSubList();
        $this->assign('sys_user_list', $sys_user);
        $this->assign('sys_user_id', SYS_USER_ID);

        $status_list = $this->logicOaLeave->getStatus();
        $this->assign('status_list', $status_list);
    }

}
